#!/bin/bash

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'

echo -e "${GREEN}开始构建可执行程序......${NC}"

if [ ! -d "build" ]; then
    mkdir -p "build"
    echo -e "${YELLOW}已创建 build 文件夹${NC}"
else
    echo -e "${YELLOW}build 文件夹已存在${NC}"
fi

cd build || { echo -e "${RED}无法进入build目录,退出!${NC}"; exit 1; }
echo -e "${GREEN}正在运行 CMake 配置...${NC}"
cmake .. || { echo -e "${RED}CMake 配置失败！${NC}"; exit 1; }
echo -e "${GREEN}正在编译项目...${NC}"
make || { echo -e "${RED}编译失败！${NC}"; exit 1; }
echo -e "${GREEN}==== 构建成功 ====${NC}"
echo -e "${GREEN}可执行文件位于: $(pwd)/${NC}"